package cn.highset.modules.base.controller.manage;

import cn.highset.common.utils.ResultUtil;
import cn.highset.common.vo.Result;
import cn.highset.modules.base.service.mybatis.ICityService;
import cn.highset.modules.base.service.mybatis.IProvinceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author Victor
 */
@Slf4j
@RestController
@Api(description = "省份表管理接口")
@RequestMapping("/highset/province")
@Transactional
public class ProvinceController {

    @Autowired
    private IProvinceService iProvinceService;
    @Autowired
    private ICityService iCityService;

    @RequestMapping(value = "/getAll", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取全部数据")
    public Result<List<Map<String, Object>>> getAll() {
        List<Map<String, Object>> list = iProvinceService.provinceList();
        list.forEach(e -> {
            e.put("children", iCityService.list(e.get("value").toString()));

        });
        return new ResultUtil<List<Map<String, Object>>>().setData(list);
    }


}
